/*
 * @Date: 2022-01-07 13:41:56
 * @Version: 1.0.0
 * @Author: chenhengling
 * @Description: 年选择器组件公共混入
 * @FilePath: \ant-year-picker\src\components\common\yearPickerMixin.js
 * @LastEditTime: 2022-01-07 14:21:11
 * @LastEditors: chenhengling
 */
export default {
  name: 'year-picker',
  inheritAttrs: false,
  components: {
    PassSlot: {
      functional: true,
      render(h, c) {
        const { cmp, args } = c.props;
        return cmp(...args);
      },
    },
  },
  model: {
    event: 'change',
  },
  props: {
    // 不支持的属性：dateRender
    placeholder: {
      type: String,
      default: '请选择年份',
    },
    format: {
      type: String,
      default: 'YYYY',
    },
  },
  data() {
    return {
      currentValue: null,
      currentOpen: null,
    };
  },
  watch: {
    value: {
      immediate: true,
      handler(val) {
        this.currentValue = val;
      },
    },
    open: {
      immediate: true,
      handler(val) {
        this.currentOpen = val;
      },
    },
    currentValue(val) {
      this.$emit('change', val);
    },
  },
  methods: {
    /**
     * @description: 面板点选日期变化
     * @param {*} val
     * @return {*}
     */
    handlePanelChange(val) {
      this.$emit('panel-change', val);
      this.currentOpen = false;

      // 点选日期默认不支持valueFormat
      if (this.valueFormat) {
        this.currentValue = this.momentToString(val, this.valueFormat);
      } else {
        this.currentValue = val;
      }
    },
    /**
     * @description: 弹窗显示状态变化
     * @param {*} val
     * @return {*}
     */
    handleOpenChange(val) {
      this.currentOpen = val;
    },
    /**
     * @description: 输入框输入日期变化
     * @param {*} val
     * @return {*}
     */
    handleChange(val) {
      this.currentValue = val;
    },
  },
};
